function getClientInfo() {
    return {
      "name" : "音符-和声",
      "category" : "AKD",
      "author" : "akd",
      "versionNumber" : 1,
      "minEditorVersion" : 65540
    };
  }

  function Mode(){
    var selectednote = SV.getMainEditor().getSelection().getSelectedNotes()
    var j = 0
    var k=[0,0,0,0,0,0,0,0,0,0,0,0]
    const kmin =0
    for(var i=0;i<12;i++){
      for(var j =0;j<selectednote.length;j++){
      if(SV.blackKey(selectednote[j].getPitch()-i)){k[i]++}
    }
  }
  for(i=1;i<12;i++){
    if(k[i]<k[kmin]){kmin= i}
  }
  return kmin
  }
  
  function main() {
    var selectednote = SV.getMainEditor().getSelection().getSelectedNotes()
    var yincheng=[2,5,4,3,1,6,0]
    var fangxiang=[1,-1]
    var myForm= {
      "title" : "和声",
      "message" : "将选中音符替换为和声",
      "buttons" : "OkCancel",
      "widgets" : [
        {
          "name" : "shoudong", "type" : "CheckBox",
          "text" : "是否手动选择调式(若自动选择则无视此选项)",
          "default" : false
        },
        {
          "name" : "diaoshi", "type" : "ComboBox",
          "label" : "调式（自动选择请无视此选项）",
          "choices" : ["C  Maj/A  min","C# Maj/A# min","D  Maj/B  min","D# Maj/C  min","E  Maj/C# min","F  Maj/D  min","F# Maj/D# min","G  Maj/E  min","G# Maj/F  min","A  Maj/F# min","A# Maj/G  min","B  Maj/G# min"],
          "default" : 0
        },
        {
          "name" : "fangxiang1", "type" : "ComboBox",
          "label" : "和声方向",
          "choices" : ["向上", "向下"],
          "default" : 0
        },
        {
          "name" : "yincheng1", "type" : "ComboBox",
          "label" : "和声音程",
          "choices" : ["三度", "六度", "五度", "四度", "二度", "七度","一度"],
          "default" : 0
        },
        {
          "name" : "bimian", "type" : "CheckBox",
          "text" : "为部分三度六度可能的不协和音程提供提供替换思路",
          "default" : false
        },
      ]};
    //var currentmode = ["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"]
    var currentmode =  ["C  Maj/A  min","C# Maj/A# min","D  Maj/B  min","D# Maj/C  min","E  Maj/C# min","F  Maj/D  min","F# Maj/D# min","G  Maj/E  min","G# Maj/F  min","A  Maj/F# min","A# Maj/G  min","B  Maj/G# min"]
    //SV.showMessageBox(Mode(),1);
  //SV.showMessageBox(currentmode[Mode()],1);
  var result = SV.showCustomDialog(myForm);
  if(result.status){
    var options = result.answers;
    const k =Mode()
    if(options.yincheng1==6){SV.showMessageBox("选中音符调式可能为",currentmode[Mode()])}
    if(options.shoudong==1){k=options.diaoshi}
    for(var i=0;i<selectednote.length;i++){
      var l=0
    if(options.bimian==1){
      if(options.yincheng1==0){if(options.fangxiang1==0){if(selectednote[i].getPitch()%12==2||selectednote[i].getPitch()%12==7){l=1}}else{if(selectednote[i].getPitch()%12==5||selectednote[i].getPitch()%12==9){l=1}}}
      if(options.yincheng1==1){if(options.fangxiang1==1){if(selectednote[i].getPitch()%12==2||selectednote[i].getPitch()%12==7){l=-1}}else{if(selectednote[i].getPitch()%12==5||selectednote[i].getPitch()%12==9){l=-1}}}
    }
   for(var j=0;j<yincheng[options.yincheng1]+l;){
    selectednote[i].setPitch(selectednote[i].getPitch()+fangxiang[options.fangxiang1])
    if(SV.blackKey(selectednote[i].getPitch()-k)==0){j++}
   }

  }
  }
    SV.finish();
  }